// editor
#include "MainStatusBar.h"
#include "editorutil.h"
#include "ScreenGDIInfo.h"

// seq
#include "seq/Project.h"
#include "seq/Sequence.h"

namespace editor {

using namespace seq;
using namespace std;

inline Project& project() { return SequencerCore::instance().getProject(); }
inline SequencerCore& seqcore() { return SequencerCore::instance(); }

MainStatusBar::MainStatusBar(int id, HWND hWnd, int x, int y, int width, int height, int minX, int minY, int offX, int offY) :
    AbstractScreen(id, x, y, width, height, minX, minY, offX, offY),
    memDC_(ScopedDC(hWnd)),
    leftOffset_(2),
    topOffset_(2),
    rightOffset_(2),
    cinfo_(g_cinfo),
    finfo_(g_finfo)
{
}

MainStatusBar::~MainStatusBar() {
}

ScreenTypes MainStatusBar::screenType() const {
    return SCREEN_MAIN_STATUS_BAR;
}

bool MainStatusBar::sendKey(short key, bool repeat) {
    return false;
}

void MainStatusBar::update() {
    memDC_.selectOwnBMP();
    COLORREF color = cinfo_.colorRef(EDTR_COLOR_MAIN_STATUS_BG);
    ScopedBrush statusBrush(color);
    FontInfo fontInfo = finfo_.fontInfo(EDTR_FONT_STATUS_FG);
    ScopedFont statusFont(fontInfo);
    memDC_.select(statusBrush);
    memDC_.select(statusFont);
    PatBlt(memDC_.get(), 0, 0, width_, height_, PATCOPY);

    SetBkColor(memDC_.get(), color);
    SetTextColor(memDC_.get(), fontInfo.color());
    std::string projName;
    if (project().projectName().empty()) {
       projName = "New Project";
    } else {
       projName = project().projectName();
    }
    if (seqcore().editPos() < 0) {
        projName += " [-]";
    } else if (seqcore().editPos() > 0) {
        projName += " [+]";
    }
    memDC_.textout(leftOffset_, topOffset_, projName);
}

void MainStatusBar::updateSize(int x, int y, int width, int height) {
    AbstractScreen::updateSize(x, y, width, height);
    memDC_.createBMP(width, height);
}

void MainStatusBar::draw() {
    memDC_.bitblt(x_, y_, width_, height_, 0, 0);
}

} // end of namespace editor
